package com.itheima_01;

/**
 * @author Xiao
 * @date 2021/7/4
 */
public class changeArray {
    public static void main(String[] args) {
        int[] arr = {19, 28, 37, 46, 50};
        System.out.println("交换前数组：");
        changeArr(arr);

        /*for (int i = 0; i < arr.length/2; i++) {
            int temp = arr[i];
            int index = arr.length - 1 - i;
            arr[i] = arr[index];
            arr[index] = temp;
        }*/
        System.out.println("------------------------");
        for (int start = 0, end = arr.length - 1; start < end; start++, end--) {
            int temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
        }

        System.out.println("交换后数组：");
        changeArr(arr);
    }

    private static void changeArr(int[] arr) {
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                System.out.print(arr[i]);
            } else {
                System.out.print(arr[i] + ",  ");
            }
        }
        System.out.println("]");
    }
}
